package com.binest.votingRecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.votingRecords.domain.VotingRecords;
import com.binest.votingRecords.service.IVotingRecordsService;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * 投票记录Controller
 * 
 * @author binest
 * @date 2024-03-28
 */
@RestController
@RequestMapping("/votingRecords")
public class VotingRecordsController extends BaseController
{
    @Autowired
    private IVotingRecordsService votingRecordsService;

    /**
     * 查询投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(VotingRecords votingRecords)
    {
        startPage();
        List<VotingRecords> list = votingRecordsService.selectVotingRecordsList(votingRecords);
        return getDataTable(list);
    }

    /**
     * 导出投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:export')")
    @Log(title = "投票记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VotingRecords votingRecords)
    {
        List<VotingRecords> list = votingRecordsService.selectVotingRecordsList(votingRecords);
        ExcelUtil<VotingRecords> util = new ExcelUtil<VotingRecords>(VotingRecords.class);
        util.exportExcel(response, list, "投票记录数据");
    }

    /**
     * 获取投票记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(votingRecordsService.selectVotingRecordsById(id));
    }

    /**
     * 新增投票记录
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:add')")
    @Log(title = "投票记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VotingRecords votingRecords)
    {
        return toAjax(votingRecordsService.insertVotingRecords(votingRecords));
    }

    /**
     * 修改投票记录
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:edit')")
    @Log(title = "投票记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VotingRecords votingRecords)
    {
        return toAjax(votingRecordsService.updateVotingRecords(votingRecords));
    }

    /**
     * 删除投票记录
     */
    @PreAuthorize("@ss.hasPermi('votingRecords:votingRecords:remove')")
    @Log(title = "投票记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(votingRecordsService.deleteVotingRecordsByIds(ids));
    }
}
